/**
 * No License Agreement. Feel free to use this code.
 */
package concurrentAPI;

import java.util.concurrent.atomic.AtomicLong;

/**
 * This class implements thread safe Sequence Generator.
 */
public class SequenceGenerator {
	
	private AtomicLong number;

	/**
	 * Creates new Sequence Generator with starting value 0.
	 */
	public SequenceGenerator() {
		this(0);
	}

	/**
	 * Creates new Sequence Generator with given starting value.
	 * 
	 * @param startWith
	 *            the starting value of the generator.
	 */
	public SequenceGenerator(long startWith) {
		this.number = new AtomicLong(startWith);
	}

	/**
	 * Increments the sequence and return the new value.
	 * 
	 * @return the next value for the sequence.
	 */
	public long next() {
		return number.getAndIncrement();
	}

	/**
	 * Use this method to retrieve the current value of the Sequence.
	 * 
	 * @return current value of the Generator as <code>long</code>.
	 */
	public long current() {
		return number.get();
	}
}
